package com.gz.im.backend.component.handler;

import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.annotation.OnConnect;
import com.corundumstudio.socketio.annotation.OnDisconnect;
import com.corundumstudio.socketio.annotation.OnEvent;
import com.gz.im.backend.component.proxy.AgentEventProxy;
import com.gz.im.backend.pojo.MessageRequest;
import lombok.extern.slf4j.Slf4j;



/**
 * @author GuoZhong
 * @description 坐席端nettySocket 处理类
 * @date 2023/3/26 22:50
 */
@Slf4j
public class AgentEventHandler {


	private final AgentEventProxy proxy;
	public AgentEventHandler(AgentEventProxy proxy) {
		this.proxy = proxy;
	}
	/**
     * 坐席端连接
     */
	@OnConnect
	public void onConnect(SocketIOClient client) {
		log.info("agent is connect");
		Long uid = Long.parseLong(client.getHandshakeData().getSingleUrlParam("uid"));
		proxy.initOnConnect(uid,client);
	}
	/**
	 * 聊天消息
	 */
	@OnEvent("chat")
	public void chat(SocketIOClient socketIOClient, AckRequest ackRequest, MessageRequest data) {
		proxy.AgentDialog(data);

	}


	/**
	 * 坐席端断开
	 */
	@OnDisconnect
	public void onDisconnect(SocketIOClient client) {
		log.info("agent is disconnect");

	}


}
